package org.dru.clay.respository.dependency;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class MappingRules {

	public static MappingRule simple(final String config) {
		return new MappingRule() {
			@Override
			public Collection<String> transform(String configuration) {
				if (config.equals(configuration)) {
					return Collections.singletonList(config);
				}
				return Collections.emptyList();
			}
		};
	}

	public static MappingRule anyToMany(final Collection<String> to) {
		return new MappingRule() {
			@Override
			public Collection<String> transform(String config) {
				return to;
			}
		};
	}

	public static MappingRule mayToMany(final Collection<String> from, final Collection<String> to) {
		return new MappingRule() {
			@Override
			public Collection<String> transform(String config) {
				if (!from.contains(config)) {
					return Collections.emptyList();
				}
				return to;
			}
		};
	}

	public static MappingRule mapRule(final Map<String, String> map) {
		return new MappingRule() {
			@Override
			public Collection<String> transform(String config) {
				if (!map.containsKey(config)) {
					return Collections.emptyList();
				}
				return Collections.singletonList(map.get(config));
			}
		};
	}
}
